package org.ysu.shoeShopping.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.ysu.shoeShopping.dao.OrderShoesDao;
import org.ysu.shoeShopping.entity.OrderShoes;
import org.ysu.shoeShopping.service.OrderShoesService;
import java.util.List;

import javax.annotation.Resource;

/**
 * 订单鞋详细(OrderShoes)表服务实现类
 *
 * @author makejava
 * @since 2025-09-13 16:59:18
 */
@Service("orderShoesService")
public class OrderShoesServiceImpl implements OrderShoesService
{
    @Resource
    private OrderShoesDao orderShoesDao;

    /**
     * 通过ID查询单条数据
     *
     * @param osid 主键
     * @return 实例对象
     */
    @Override
    public OrderShoes queryById(Integer osid) {
        return this.orderShoesDao.queryById(osid);
    }

    /**
     * 分页查询
     *
     * @param orderShoes 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<OrderShoes> queryByPage(OrderShoes orderShoes, PageRequest pageRequest) {
        long total = this.orderShoesDao.count(orderShoes);
        return new PageImpl<>(this.orderShoesDao.queryAllByLimit(orderShoes, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param orderShoes 实例对象
     * @return 实例对象
     */
    @Override
    public OrderShoes insert(OrderShoes orderShoes) {
        this.orderShoesDao.insert(orderShoes);
        return orderShoes;
    }

    /**
     * 修改数据
     *
     * @param orderShoes 实例对象
     * @return 实例对象
     */
    @Override
    public OrderShoes update(OrderShoes orderShoes) {
        this.orderShoesDao.update(orderShoes);
        return this.queryById(orderShoes.getOsid());
    }

    /**
     * 通过主键删除数据
     *
     * @param osid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer osid) {
        return this.orderShoesDao.deleteById(osid) > 0;
    }

    /**
     * 根据订单ID查询订单商品列表
     *
     * @param orderId 订单ID
     * @return 订单商品列表
     */
    @Override
    public List<OrderShoes> findByOrderId(Integer orderId) {
        return this.orderShoesDao.findByOrderId(orderId);
    }
}
